import '../model/log.dart';

void noop(dynamic msg) => {};

typedef Resolve = void Function(dynamic msg);
typedef NormalLogPipe = void Function(List<NormalLog> msg, Resolve resolve);

/// 生成管道
/// 至少传入一个 pipe 函数
/// 该函数会将传进来的Pipe一层一层包起来
Function createPipeline(List<Function> pipeline) {
  // // 单元素不允许reduce
  if (pipeline.isEmpty) {
    throw 'the pipeline list must have at least one element';
  }

  return pipeline.reduce((prePipe, pipe) =>
      (msg, [nextPipe = noop]) => prePipe(msg, (msg) => pipe(msg, nextPipe)));
}
